package com.zhu.collection.impl;

import com.zhu.collection.Set;
import com.zhu.linkedlist.MyLinkedList;

/**
 * 基于链表实现的集合
 * @author: zhu
 * @date: 2019/1/16 09:34
 */
public class LinkedListSet<E> implements Set<E> {

    private MyLinkedList<E> list;
    public LinkedListSet(){
        list = new MyLinkedList<>();
    }

    @Override
    public void add(E e) {
        if (!list.contains(e))
            list.addFirst(e);
    }

    @Override
    public void remove(E e) {
        list.remove(e);
    }

    @Override
    public boolean contains(E e) {
        return list.contains(e);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }
}
